package com.xx.account.controller;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.xx.account.mapper.AccountRecordMapper;
import com.xx.common.core.domain.entity.SysUser;
import com.xx.common.utils.DateUtils;
import com.xx.common.utils.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xx.common.annotation.Log;
import com.xx.common.core.controller.BaseController;
import com.xx.common.core.domain.AjaxResult;
import com.xx.common.enums.BusinessType;
import com.xx.account.domain.AccountRecord;
import com.xx.account.service.IAccountRecordService;
import com.xx.common.utils.poi.ExcelUtil;
import com.xx.common.core.page.TableDataInfo;

/**
 * 接单Controller
 *
 * @author ruoyi
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/account/record")
public class AccountRecordController extends BaseController
{
    @Resource
    private IAccountRecordService accountRecordService;

    @Resource
    private AccountRecordMapper accountRecordMapper;

    /**
     * 查询接单列表
     */
    @PreAuthorize("@ss.hasPermi('account:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountRecord accountRecord)
    {
        startPage();
        List<AccountRecord> list = accountRecordService.selectAccountRecordList(accountRecord);
        return getDataTable(list);
    }

    /**
     * 查询接单列表统计数据
     */
    @GetMapping("/listDataSum")
    public AjaxResult listDataSum(AccountRecord accountRecord)
    {
        return success(accountRecordService.listDataSum(accountRecord));
    }

    /**
     * 导出老板放单列表
     */
    @PreAuthorize("@ss.hasPermi('account:record:export')")
    @Log(title = "导出老板放单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountRecord accountRecord)
    {
        accountRecordService.export(response, accountRecord);
    }

    /**
     * 导出投手接单列表
     */
    @PreAuthorize("@ss.hasPermi('account:record:exportByWorker')")
    @Log(title = "导出投手接单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/exportByWorker")
    public void exportByWorker(HttpServletResponse response, AccountRecord accountRecord)
    {
        accountRecordService.exportByWorker(response, accountRecord);
    }

    /**
     * 获取接单详细信息
     */
    @PreAuthorize("@ss.hasPermi('account:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(accountRecordService.selectAccountRecordById(id));
    }

    /**
     * 新增接单
     */
    @PreAuthorize("@ss.hasPermi('account:record:add')")
    @Log(title = "接单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountRecord accountRecord)
    {
        return toAjax(accountRecordService.insertAccountRecord(accountRecord));
    }

    /**
     * 修改接单
     */
    @PreAuthorize("@ss.hasPermi('account:record:edit')")
    @Log(title = "接单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountRecord accountRecord)
    {
        return toAjax(accountRecordService.updateAccountRecord(accountRecord));
    }

    /**
     * 切换交单状态
     */
    @PreAuthorize("@ss.hasPermi('account:record:switchIsSuccess')")
    @Log(title = "切换交单状态", businessType = BusinessType.UPDATE)
    @PutMapping("/switchIsSuccess")
    public AjaxResult switchIsSuccess(@RequestBody AccountRecord accountRecord)
    {
        return toAjax(accountRecordService.switchIsSuccess(accountRecord));
    }

    /**
     * 删除接单
     */
    @PreAuthorize("@ss.hasPermi('account:record:remove')")
    @Log(title = "接单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(accountRecordService.deleteAccountRecordByIds(ids));
    }
}
